# Maintainer: Dominic Sisneros <dsisnero@gmail.com>

_realname=lasem
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.4
pkgrel=3
pkgdesc="Lasem aims to be a C/Gobject based SVG/Mathml renderer (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://wiki.gnome.org/Projects/Lasem"
license=('LGPL')
license=('GPL' 'MPL' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
             "${MINGW_PACKAGE_PREFIX}-glib2"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-cairo"
             "${MINGW_PACKAGE_PREFIX}-pango"
             "${MINGW_PACKAGE_PREFIX}-libxml2"
             "${MINGW_PACKAGE_PREFIX}-python"
             "flex"
             "bison"
             "intltool"           
            )
source=("https://download.gnome.org/sources/${_realname}/${pkgver:0:3}/${_realname}-$pkgver.tar.xz"
        CVE-2013-7447.patch
        001-fix-doc-install.patch
        002-no-undefined.patch
        install-mathml-headers.patch)
sha256sums=('9bf01fcfdc913ebc05989ac1f5902d52e28e7c31f797e2b6d3d413d4b51bba39'
            'd9e836934655db45e52f6ab1923866a5010a071c1c62fcbcb6c2fd999e978d2c'
            '9c9321e4f2c841d3b348204519b5e508492521f4c2c512ecfb8a083a06dca1e3'
            '7f98e6d191c53ffe80235258c5114c78e3e7af889c5c07c79ed4134e2be7e3b8'
            'bd106104f239557a7e63b7174516b45ea40492b5f02d5bc8abb55efb7e734034')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/CVE-2013-7447.patch
  patch -p1 -i ${srcdir}/001-fix-doc-install.patch
  patch -p1 -i ${srcdir}/002-no-undefined.patch
  patch -p1 -i ${srcdir}/install-mathml-headers.patch
  autoreconf -fiv 
}

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir -p ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}
  #Force intltool to use the MSYS perl version to avoid LibXML issue
  #That occurs in the Win32 version of Perl with the intltool.
  INTLTOOL_PERL=/usr/bin/perl \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --enable-gtk-doc

  make
}

check() {
   cd "${srcdir}/build-${MSYSTEM}"
   make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" -j1 install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
